/****************广告js库*****2020-2-3****************/

//创建一个weindow的常用对象
/*常用方法封装   strta*/
class wd {
	constructor() {
		this.wd = window;
		this.Dom = this.wd.document;
		this.sess = this.wd.sessionStorage;
		this.local = this.wd.localStorage;
		this.GetUerl = this.wd.location;
		this.xhr = new XMLHttpRequest() || new ActiveXObject("Microsoft.XMLHTTP");
	}
}

class Ajax extends wd {
	constructor(parameter) {
		super();
		/*Content-type (几种常见的Content-Type类型)
		application/x-www-form-urlencoded
		multipart/form-data
		application/json
		text/xml
		application/json;charset=UTF-8
		*/
		const {
			url = null, data = {}, header = 'application/json;charset=UTF-8', way = 'post', datatype = 'JSON'
		} = parameter;

		return new Promise((resolve, reject) => {
			let xhr = this.xhr;
			xhr.open(way, url, true);
			xhr.datatype = datatype;
			xhr.setRequestHeader('Content-type', `${header}`);
			xhr.timeout = 30000;
			if (xhr && xhr.timeout) {
				xhr.ontimeout = function() { /*请求超时触发的事件*/
					alert('请求超时!')
				};
			}
			xhr.send(JSON.stringify(data));
			xhr.onerror = function(e) { /*失败*/
				reject(new Error({
					errorType: 'abort_error',
					xhr: xhr
				}));
			};
			xhr.onreadystatechange = function() {
				if (xhr.readyState === 4 && xhr.status === 200) {
					resolve(JSON.parse(xhr.responseText))
				} else if (xhr.readyState >= 400 && xhr.status < 500) {
					reject(`错误请求，如语法错误http=>状态码:${xhr.readyState}`)
				} else if (xhr.status > 500) {
					reject(`服务器产生内部错误http=>状态码:${xhr.readyState}`)
				}
			}
		})
	}
}


class session extends wd { // 封装sessionStorage 继承 wd 方法
	constructor(sess) { // 默认为sessionStorage 传入参数为localStorage 
		super(); //超类
		this.storage = sess === undefined ? this.sess : this.local;
	}
	set(key, value) {
		this.storage.setItem(this.wd.btoa(this.wd.encodeURIComponent(key)), this.wd.btoa(this.wd.encodeURIComponent(value)));
	}
	get(key) {
		let data = key === undefined ? null : this.storage.getItem(this.wd.btoa(this.wd.encodeURIComponent(key)));
		return data && this.wd.atob(this.wd.decodeURIComponent(data));
	}
	removeKey(key) {
		key && this.storage.removeItem(this.wd.decodeURIComponent(this.wd.btoa(key)));
	}
	removeAll() {
		this.storage.clear();
	}
}

class FindDom extends wd {
	constructor() {
		super();
	}

	/**
	 * 创建一个html标签 默认为div
	 * @param label
	 * @returns {HTMLDivElement}
	 */
	setElement(label = 'div') { //创建标签
		return this.Dom.createElement(label)
	}

	/**
	 *
	 * @param node 需要插入的节点
	 * @param place 需要插入的位置 （beforebegin: 元素自身的前面。afterbegin: 插入元素内部的第一个子节点之前。beforeend: 插入元素内部的最后一个子节点之后。afterend: 元素自身的后面）
	 * @param text 需要的html文本
	 */
	insertion(node, place, text) { //插入html标签到指定位置
		node && node.insertAdjacentHTML(place, text);
	}

	/*查找DOM start */
	/**
	 * @param {Object} id
	 * @param {string} Node father(父级) son(子级) noe (第一个) end(最后一个) upwith(同级前元素) withnext(同级后元素) sonCont(返回子节点个数)
	 */
	getId(id, Node) {
		let d = this.Dom.getElementById(id)
		if (id && Node === undefined) {
			return d
		}
		if (id && Node)
			return Node === 'father' ? d.parentNode : Node === 'son' ? d.lastElementChild : Node === 'noe' ? d.firstElementChild ||
				d.firstChild : Node === 'end' ? d.firstChild : Node === "upwith" ? d.previousElementSibling : Node === 'withnext' ?
				d.nextElementSibling : Node === 'sonCont' ? d.childElementCount : null;
	}

	/**
	 * 以class来获取DOM
	 * @param name 传入class
	 * @returns {HTMLCollectionOf<Element>}
	 */
	getClass(name) {
		return this.Dom.getElementsByClassName(name)
	}

	/***
	 * 以标签名来获取DOM
	 * @param name 传入标签名
	 * @returns {HTMLCollectionOf<HTMLElementTagNameMap[*]>}
	 */
	getName(name) {
		return this.Dom.getElementsByTagName(name)
	}

	/**
	 * 获取所有相同的标签
	 * @param All 传入 id class 或html 标签
	 * @returns {NodeListOf<HTMLElementTagNameMap[*]>}
	 */
	getAll(All) {
		return this.Dom.querySelectorAll(All)
	}

	/**
	 * 以属性获取DOM
	 * @param leba 传入属性 如 typ=file
	 * @returns {any}
	 */
	getSelector(leba) {
		return this.Dom.querySelector(leba);
	}

	/**
	 * 返回body
	 * @returns {HTMLElement}
	 */
	getBody() {
		return this.Dom.body;
	}
	/*查找DOM end */

}

//常用操作 方法
class func extends wd {
	constructor() {
		super();
	}

	/**
	 * 传入数组返回出现次数最对的值
	 * @param {arr} arrlist
	 */
	much(arrlist) {
		const d = {}
		arrlist.forEach(k => !d[k] ? d[k] = 1 : d[k]++)
		const max = Object.keys(d).sort((a, b) => d[b] - d[a])[0]
		return max
	};
	/**
	 * 获取当前设备类型
	 * 不传入阐述就返回PC端 || 移动端
	 * 传入参数为移动端设备类型
	 */
	getFtu(type = null) {
		let userAgentInfo = navigator.userAgent,
			flag, terminal = ['Android', 'iPhone', 'SymbianOS', 'Windows Phone', 'iPad', 'iPod'];
		if (type) {
			for (let i in terminal) {
				if (userAgentInfo.includes(terminal[i])) {
					return terminal[i];
				}
			}
			return 'PC端';
		} else {
			for (let v = 0; v < terminal.length; v++) {
				if (userAgentInfo.indexOf(terminal[v]) > 0) {
					flag = '移动端';
					break
				}
			}
			return flag === '移动端' ? '移动端' : 'PC端';
		}
	};
	/**
	 * @param {string} url 传入固定的表示,返回对应的数据
	 */
	getUrl(url) {
		switch (url) {
			case 'www': // 获取当前协议 + 域名
				return `${this.GetUerl.protocol + "//" + this.GetUerl.host}/`;
			case 'son': // //获取当前子目录
				return this.GetUerl.pathname;
			case 'port': //获取当前端口
				return this.GetUerl.port;
			case 'search': //获取当域名?号后面的参数
				return this.GetUerl.search;
			case 'url': //返回当前的url
				return this.GetUerl.href;
			case 'tp': //返回当协议 http|https
				return this.GetUerl.protocol;
			case 'host': //返回当前的域名
				return this.GetUerl.host
			default: // 以上匹配失败
				return null
		}
	}

	/**
	 * 传入数组 返回当前最大值
	 * @param arr
	 * @returns {number}
	 */
	max(arr) {
		return Math.max(...arr); //es6
		// return Math.max.apply(this,arr); //es5
	}
	/**
	 * 传入数组 返回当前最小值
	 * @param arr
	 * @returns {number}
	 */
	min(arr) {
		return Math.min(...arr);
	}
	/**
	 * //禁止代码调试
	 * @param ban
	 * @constructor
	 */
	BanDebugging(ban) {
		let {
			Noright = false, NoKeyDown = false, debug = false
		} = ban;
		if (Noright) { //禁止鼠标右键
			this.onkeydown = this.onkeyup = this.onkeypress = function() {
				this.event.returnValue = false;
				return false;
			}
		}
		if (NoKeyDown) { //禁止F12
			let h = this.innerHeight,
				w = this.innerWidth;
			this.onresize = function() {
				if (h !== this.innerHeight || w !== this.innerWidth) {
					this.close();
					this.location = "about:blank";
				}
			}
		}
		if (debug) { //反调试代码
			! function() {
				const handler = setInterval(() => {
					const before = new Date();
					debugger;
					const after = new Date();
					// 如果不打开调试模式的话,肯定不会大于100
					const cost = after.getTime() - before.getTime();
					if (cost > 100) {
						clearInterval(handler)
					}
				}, 1000)
			}();
		}
	}
	/**
	 * 生成随机数
	 * @param {*} lower 
	 * @param {*} upper 
	 */
	randoms(lower, upper) {
		return Math.floor(Math.random() * (upper - lower)) + lower;
	}
	/**
	 * 伪类数组鉴别以及转换
	 * @param {Object} ar
	 * @return {true/false}
	 */
	ToIdentify(ar){
		return ar.push || ar.pop || ar.map || ar.shift === undefined ? [...ar] : ar;
	}
}

/***************常用方法 end********************/

var $ = new FindDom();
var f = new func();

/*************js 广告方法********************/

/******************统计器************************/
class statistics extends FindDom {
	/**
	 * @param {string} url
	 */
	constructor(url = 'https://js.users.51.la/19651791.js') {
		super();
		this.init(url);
	}
	init(url) {
		const script = this.setElement('script');
		script.type = 'text/javascript';
		script.src = url;
		this.getAll('head')[0].appendChild(script);
	}
}

class template extends FindDom {

	/**
	 * @param {string} site 模板位置 可选 top ， bottom ， conter ，letft ，right
	 * @param {url} a  跳转目标地址
	 * @param {string} img 广告图片
	 * @param {string} id 广告模板id 默认为 repetitioncols
	 */
	constructor(...argument) {
		super();
		this.restyle();
		this.init(...argument)
	}
	init(order) {
		let {
			site,
			id = '',
			className = '',
			sqcont = [],
		} = order;

		console.log(sqcont);
		let {
			link,
			img
		} = new randomUrl().AtwillImg(sqcont);
		const include = 'position: fixed; z-index: 99999999999 !important;'
		const MTplaceLits = {
			top: `z-index: 99999999999 !important;width:100%; height:20%;`,
			bottom: `${include}width: 100%;bottom: 0;`,
			letft: `${include}width: 20%;bottom: 0;left: 0;top: 10%;`,
			right: `${include}width: 20%;bottom: 0;right: 0;top: 10%;`,
			conter: `${include} position: fixed; top: 0; bottom: 0; left: 0;  margin: auto; height: 50vh; width: 100%;`,
		};
		const MTtemplate = {
			top: `<a href="${link}">
					<img style='width: 100%; height: 300px;' src="${img}" alt="">
					</a>`,
			bottom: `<div class="up animated"><p style="position: absolute;right: 0px;background: white;top: -22vh; width: 3rem;" id="close">关闭</p><a href="${link}">
					<img style='position: fixed;width: 100%; height: 340px; bottom: 0px;z-index: 9999999999;' src="${img}" alt="">
					</a></div>`,

			conter: `<p style="position: absolute;right: 0px;background: white; width: 3rem;" id="close">关闭</p>
			<a  href="${link}">
			<img class="main_img img-hover" src="${img}" style="background-color: rgba(0, 0, 0,0.4); width: 100%; height: 50vh;object-fit: none;">
			</a>`,
		};
		const first = document.body.firstElementChild; //获取body第一个原数
		let tp = this.setElement();
		switch (site) {
			case 'top':
				tp.id = id;
				tp.className = className;
				tp.style = MTplaceLits.top;
				tp.innerHTML = MTtemplate.top;
				this.getBody().insertBefore(tp, first);
				return false;
			case 'bottom':
				tp.id = id;
				tp.className = className;
				tp.style = MTplaceLits.bottom;
				tp.innerHTML = MTtemplate.bottom;
				this.getBody().insertBefore(tp, first);
				return false;
			case 'conter':
				tp.id = id;
				tp.className = className;
				tp.style = MTplaceLits.conter;
				tp.innerHTML = MTtemplate.conter;
				this.getBody().insertBefore(tp, first);
				return false;
			case 'letft':
				tp.id = id;
				tp.className = className;
				tp.style = MTplaceLits.letft;
				tp.innerHTML = MTtemplate.conter;
				this.getBody().insertBefore(tp, first);
				return false;
			case 'right':
				tp.id = id;
				tp.className = className;
				tp.style = MTplaceLits.right;
				tp.innerHTML = MTtemplate.conter;
				this.getBody().insertBefore(tp, first);
				return false;
		}
	}
	pc(pctp, a, img) {
		let cons = true;

		cons === true || this.style();
		cons = false;

		//pc 模板
		const PublicList = {
			w_index: `width: 100%;z-index: 999999999 !important;`,
			p_fixed: `position: fixed;`,
			h_height: `height: 15vh;`,
			w_width: `width: 15vh;`,
		};
		const PCStyle = {
			top: `${PublicList.w_index}${PublicList.h_height}`,
			bottom: `${PublicList.p_fixed} bottom: 0; ${PublicList.w_index} ${PublicList.h_height}`,
			conter: `${PublicList.w_index} ${PublicList.p_fixed}top: 0; bottom: 0; left: 0;  margin: auto; height: 50vh; width: 80%; margin-left:10%;`,
			letft: `${PublicList.w_index} ${PublicList.p_fixed}top: 0; bottom: 0; left: 0; margin: auto; ${PublicList.h_height} ${PublicList.w_width}`,
			right: `${PublicList.w_index} ${PublicList.p_fixed}top: 0; bottom: 0; right: 0; margin: auto; ${PublicList.h_height} ${PublicList.w_width}`,
		};
		const PCtemplate = {
			top: `<img src="http://www.okbj.top/wp-content/uploads/2019/12/KOREAN-BJ-2019121910.jpg" alt="" class="" style='width: 100%; height: 15vh; object-fit: none;'>`,
			bottom: `<img src="${img}" alt="" class=" up animated" style='width: 100%; height: 15vh; object-fit: none;'>`,
			conter: `<div class="up animated"><p style="position: absolute;right: 0px;background: white;" id="close">关闭</p>
			<a  href="${a}">
			<img src="${img}" style="background-color: rgba(0, 0, 0,0.4); width: 100%; height: 167.852px;height: 50vh;object-fit: none;">
			</a></div>`
		};
		const first = document.body.firstElementChild; //获取body第一个原数
		let tp = this.setElement();
		switch (pctp) {
			case 'top':
				tp.id = id;
				tp.className = className;
				tp.style = PCStyle.top;
				tp.innerHTML = PCStyle.top;
				this.getBody().insertBefore(tp, first);
				return false;
			case 'bottom':
				tp.id = id;
				tp.className = className;
				tp.style = PCStyle.bottom;
				tp.innerHTML = PCStyle.bottom;
				this.getBody().insertBefore(tp, first);
				return false;
			case 'conter':
				tp.id = id;
				tp.className = className;
				tp.style = PCStyle.conter;
				tp.innerHTML = PCtemplate.conter;
				this.getBody().insertBefore(tp, first);
				return false;
			case 'letft':
				tp.id = id;
				tp.className = className;
				tp.style = PCStyle.letft;
				tp.innerHTML = PCtemplate.conter;
				this.getBody().insertBefore(tp, first);
				return false;
			case 'right':
				tp.id = id;
				tp.className = className;
				tp.style = PCStyle.right;
				tp.innerHTML = PCtemplate.conter;
				this.getBody().insertBefore(tp, first);
				return false;
		}
	}
	restyle() {
		/**
		 * 添加抖动动画
		 */
		if (!this.getId('setstyle')) {
			const Frames =
				`.animated{animation-duration: 0.5s;/*动画时间*/animation-fill-mode: forwards;/*播放后的状态*/animation-iteration-count: infinite;/*动作循环的次数：infinite 无限循环*/animation-duration: 2s;/*动画时间*/}.up{animation-name: upAnimation;/*动画的名称*/transform-origin: center bottom;/*设置动画旋转元素的基点为*/cursor: pointer;}@keyframes upAnimation{0%,100%,20%,50%,80%{transition-timing-function: cubic-bezier(0.215, .61, .355, 1);transform: translate3d(0, 0, 0);}40%,43%{transition-timing-function: cubic-bezier(0.755, 0.50, 0.855, 0.060);transform: translate3d(0, -30px, 0);}70%{transition-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);transform: translate3d(0, -15px, 0);}90%{transform: translate3d(0, -4px, 0);}}`;
			// 创建style标签
			const style = this.setElement('style');
			// 设置style属性
			style.type = 'text/css';
			style.id = 'setstyle'
			// 将 keyframes样式写入style内
			style.innerHTML = Frames;
			// 将style样式存放到head标签
			this.getAll('head')[0].appendChild(style);
		}
	}
}

//广告关闭
class colos extends FindDom {
	constructor() {
		super();
		setTimeout(() => {
			let cilCk = this.getAll('#close');
			for (let cols = 0; cols < cilCk.length; cols++) {
				cilCk[cols].onclick = function() {
					this.parentNode.innerHTML = null;
				}
			}
		}, 500);
	}
}

//删除gif图片
class deleteEndGif extends FindDom {
	constructor() {
		super();
		this.init();
	}
	init() {
		let gif = this.getAll('img');
		for (let p = 0; p < gif.length; p++) {
			if (gif[p].src && gif[p].src.includes('gif')) {
				if (gif[p].parentNode) {
					gif[p].parentNode.innerHTML = null;
				} else {
					gif[p].innerHTML = null;
				}
			}
		}
	}
}
//替换a标签链接
class ReplaceTheLink extends func {
	constructor(parameter) {
		super();
		let {link,node,bg,onOff = false} = parameter;
		 //数组鉴别以及转化 是A及返回当前元素
		 node = node.tagName === 'A' ? node : this.ToIdentify(node);
		if (node instanceof Object && typeof link === 'string' && typeof bg === 'string') { //传入的单个
			link || node.remove();
            node.href = link;
			node.style.backgroundImage = `url(${bg})`;
		} else if (node instanceof Array && link instanceof Array && bg instanceof Array) {
			for (let p = 0; p < node.length;p++) {
				if (link[p] && node[p] && bg[p]) {
					node[p].href = link[p];
					node[p].style.backgroundImage = `url(${bg[p]})`;
				} else {
					onOff && node[p].remove();
				}
			}
		}
	}
}

//删除a的背景图片
class ChooseToReplace extends FindDom {
	constructor(data = {}) {
		super();
		let {barring = [], url = '',bg = [], onOff = false} = data;
		let lo, addressBar, AClassName, location, bgrul, ahref;
		lo = new func();
		location = `${lo.getUrl('tp') + "//" + lo.getUrl('host')}`;
		//当前的连接不包含当前的地址 有些网址的图片可能放在不同的服务器 传入参数就根据参数中的地址栏来判断当前的图片是否是广告
		addressBar = barring === []  ? location : barring;
        AClassName = this.getAll('a');
		for (let i = 0 ; i < AClassName.length; i++) {
			ahref = AClassName[i].href;
			bgrul = getComputedStyle(AClassName[i], null).getPropertyValue('background-image').replace("url(",'').replace(")",'');
			//已有传入的数组（过滤的图片以及链接，以及替换的图片链接）
		   if (addressBar.length > 1 && typeof url === 'object' && bg instanceof Array) {
			   for(let s in addressBar) {
			   		  if(!bgrul.includes(addressBar[s]) || !ahref.includes(addressBar[s])) {  //过滤图片链接和地址链接，以及传入的地址
						//替换地址方法
						new ReplaceTheLink({link:url[i] !== undefined ? url[i] : onOff === true ? '' : location,node:AClassName[i],bg:bg[i],onOff:onOff})
						  //过滤出来不是本网站和自己的过滤项的操作
						  	// url !== '' ? AClassName[pl].href = url : (AClassName[pl].remove()); //传入url就替换，不然删除
			   		  }
			   }
		   }else { //没有过滤项以及替换的地址
			   if (!bgrul.includes(addressBar) || !ahref.includes(addressBar)) {
			   	url !== '' ? AClassName[pl].href = url : (AClassName[pl].remove());
			   	console.log('ClasName')
			   }
		   }
		}
		// for (let pl = 0; pl < AClassName.length; pl++) {
		// 	ahref = AClassName[pl].href;
		// 	bgrul = window.getComputedStyle(AClassName[pl], null).getPropertyValue('background-image').replace("url(", '').replace(")", '');
  //           console.log(ahref)
  //           console.log(bgrul)
		// 	if (!bgrul.includes(addressBar) || !ahref.includes(addressBar)) {
		// 		url !== '' ? AClassName[pl].href = url : (AClassName[pl].remove());
		// 		console.log('ClasName')
		// 	}
		// }
	}

}

//随机生成网址
class randomUrl extends func {
	constructor() {
		super();
	}
	/**
	 * 返回随机的网址
	 * @param s 传入数组
	 * @returns {*}  返回数组中任意的数据
	 */
	AtwillUrl(s) {
		return s[this.randoms(0, s.length)];
	}
	/**
	 * 返回随机的广告和对应的广告地址
	 * @param obj
	 * @returns {{link: (string), img: (string)}}
	 * @constructor
	 */
	AtwillImg(obj) {
		let One = obj[this.randoms(0, obj.length)];
		return {
			link: One.link,
			img: One.img
		}
	}
}


//屏幕任何位置点击跳转页面
class arbitrarilyClick extends func {
	constructor(data) {
		super();
		this.init(data);
	}
	init(data) {
		let {
			jumpTerm = false, linkUrl = null, download = false, dwAPK = null
		} = data;

		if (linkUrl instanceof Array) {
			linkUrl = new randomUrl().AtwillUrl(linkUrl);
		}
		sessionStorage.getItem(`${this.getUrl('url')}`) || sessionStorage.setItem(`${this.getUrl('url')}`, true);
		if (sessionStorage.getItem(`${this.getUrl('url')}`) === 'true' || jumpTerm || download) {
			let mb = $.setElement();
			mb.id = 'meban';
			mb.style = `position: fixed;width: 100vh; height: 100vh;top: 0px; z-index: 9999999999999;`;
			$.getBody().appendChild(mb);
		}

		let clic = $.getAll('#meban');
		let _this = this;
		for (let i = 0; i < clic.length; i++) {
			clic[i].onclick = function() {
				clic.forEach((tiem) => {
					$.getBody().removeChild(tiem)
				})
				if (_this.getFtu('null') === 'Android') {
					if (sessionStorage.getItem(`${_this.getUrl('url')}`) === 'true') {
						sessionStorage.setItem(`${_this.getUrl('url')}`, false);
						if (download) {
							const ele = $.setElement('a');
							ele.setAttribute('href', dwAPK); //设置下载文件的url地址
							ele.setAttribute('download', 'download'); //用于设置下载文件的文件名
							ele.click();
							jumpTerm && window.open(linkUrl);
							jumpTerm = false;
							download = false;
						}
						jumpTerm && window.open(linkUrl);
						jumpTerm = false;
					}
				} else {

					if (sessionStorage.getItem(`${_this.getUrl('url')}`) === 'true') {
						sessionStorage.setItem(`${_this.getUrl('url')}`, false)
						window.open(linkUrl);
					}
				}
			}
		}
	}
}

//js正则匹配规
class regular {
	/**
	 * @param {Array} arrcont  额外匹配规则
	 * @param {url} sfUrl 私服地址
	 * @param {url}  匹配失败后地址存入数据库的服务器地址
	 * */
	constructor(parameter = {}) {
		this.init(parameter);
	}
	init(parameter) {

		let {
			AllCont = [], sfUrl = 'https://ecalling.com.cn/list1.php?c=pk10', API = 'http://172.16.100.52/api/'
		} = parameter;

		let mj = {
			iframe: `<iframe src='${sfUrl}' style='width: 100% !important; height: 2000vh !important;' scrolling='no' frameborder='0'></iframe>`,
		};
		setTimeout(() => {
			let BOM = $.getAll('iframe');
			let arrt = [];
			if (BOM.length !== 0) {
				for (let p = 0; p < BOM.length; p++) {
					arrt.push(parseInt(BOM[p].height));
				}
				console.warn(arrt);
				if (arrt.length !== 0) {
					BOM[arrt.indexOf(Math.max.apply(null, arrt))].src = this.url;
				};
				console.warn('iframe');
			} else {
				var tb = $.getAll('table');
				// tb.length !== 0 ? tb[0].innerHTML = mj.iframe; :  Ajax({url: window.location.href,count: 1});
				if (tb.length !== 0) {
					//  tb[Math.ceil((tb.length+1)/2)].innerHTML = mj.iframe;
					tb[0].innerHTML = mj.iframe;
					console.warn('table');
				} else {
					let Arrcont = ["#content", ".content", "center", ".center", "#center", ...AllCont];
					for (var x = 0; x < Arrcont.length; x++) {
						var zdy = $.getAll(Arrcont[x]);
						if (zdy.length !== 0) {
							break;
						}
					};
					if (zdy.length !== 0) {
						zdy[0].innerHTML = mj.iframe;

					} else {
						new Ajax({
							url: API,
							data: {
								url: window.location.href,
								count: 1
							}
						})
					};
				}
			}
		}, 500);
	}
}



/**************广告过滤********************/
class filterImg extends func {
	constructor() {
		super();
		this.init();
	}
	init() {
		let ImgWidtArrylis = [];
		let ImgHeightArrylis = [];
		let imgs = $.getAll('img');
		for (let s = 0; s < imgs.length; s++) {
			if (imgs[s].src && imgs[s].src.includes('gif')) {
				if (imgs[s].parentNode) {
					imgs[s].parentNode.innerHTML = null;
				}
			}
			if (imgs[s] && imgs[s].width > 850) { //清楚部分
				imgs[s].style.display = 'none';
			}
			if (imgs[s].style && imgs[s].style.width === '100%') {
				imgs[s].style.display = 'none';
			} else {
				if (imgs[s].style && imgs[s].style.display !== 'none') {
					ImgWidtArrylis.push(imgs[s].width)
					ImgHeightArrylis.push(imgs[s].height)
				}
			}
		}
		for (let p = 0; p < imgs.length; p++) {
			//数据的宽高一直
			if (imgs[p].width && parseInt(imgs[p].width) !== parseInt(this.much(ImgWidtArrylis)) && parseInt(imgs[p].height) !==
				parseInt(this.much(ImgHeightArrylis))) {
				if (parseInt(imgs[p].width) > 300 && parseInt(imgs[p].height) > 200) {

				} else {
					if (imgs[p].parentNode !== undefined && imgs[p].parentNode !== null) {
						imgs[p].parentNode.innerHTML = null;
					}
				}
			}
		}
		/**
		 * 删除父元素为a标签并且href开始为http 或者为https开始得图片
		 */
		let img = $.getAll('img');

		for (let s = 0; s < img.length; s++) {
			if (img[s].width !== this.much(ImgWidtArrylis) && img[s].height !== this.much(ImgHeightArrylis)) {
				if (img[s] === 'object' && img[s].style !== undefined && img[s].style.display !== undefined) {
					if (img[s].parentNode !== undefined) {
						img[s].parentNode.innerHTML = null
					}
					img[s].style.display = 'none';
				}
			} else {
				/**
				 * 获取父元素是否有href 如果是父元素就为a标签
				 */
				if (img[s].parentNode && img[s].parentNode.href) {
					if (img[s].parentNode.href.includes('http')) {
						if (img[s].style.width !== this.much(ImgWidtArrylis)) {
							img[s].parentNode.style.display = 'none';
							if (img[s].parentNode !== undefined) {
								img[s].parentNode.innerHTML = null
							}
						}
					} else if (img[s].parentNode.href.includes('https')) {
						if (img[s].style.width !== this.much(ImgWidtArrylis)) {
							if (img[s].parentNode !== undefined) {
								img[s].parentNode.innerHTML = null
							}
							img[s].parentNode.style.display = 'none';
						}
					}
				} else {
					if (img[s] === 'object') {
						img[s].style.display = 'none';
					}
				}
			}
		}
	}
}

/********小说 电影广告配置***********/
class FictionMovie extends func {
	constructor(data) {
		super()
		new statistics();
		this.init(data)
	}
	init(data) {
		let {
			top,
			tcont = [],
			bottom,
			bcont = [],
			removegif = true,
			OneClick = {
				click: false,
				dwApp: false,
				AppUrl: null,
				url: null,
			},
		} = data;
		//是否开删除GIF
		removegif && new deleteEndGif();
		if (this.getFtu() === '移动端') {
			console.log(OneClick)
			//是否开启屏幕任意点击事件 ， 并传入参数
			OneClick.click && new arbitrarilyClick({
				jumpTerm: OneClick.off,
				linkUrl: OneClick.url,
				download: OneClick.dwApp,
				dwAPK: OneClick.AppUrl
			});

			if (this.getUrl('www') !== this.getUrl('url')) {
				if (document.getElementsByClassName('AdvertisingLogo').length === 0) {
					let body = document.body;
					if (top) {
						let OenData = tcont.length === 1 ? tcont[0] : new randomUrl().AtwillImg(tcont);
						let {
							link,
							img
						} = OenData;
						let theaTop = new FindDom().setElement();
						theaTop.className = 'AdvertisingLogo';
						theaTop.innerHTML =
							`<a href="${link}" target="_blank" rel="noopener noreferrer"><img src="${img}" alt="" class="wp-image-66839"  sizes="(max-width: 800px) 100vw, 800px" style="width: 100%; height: 15vh;"></a>`;
						body.insertBefore && body.insertBefore(theaTop, body.firstChild);
					}

					bottom === true ? setTimeout(function() {
						let OenData = bcont.length === 1 ? bcont[0] : new randomUrl().AtwillImg(bcont);
						let {
							link,
							img
						} = OenData;
						let bottom = new FindDom().setElement();
						bottom.style = 'z-index: 9999999;width: 100%;';
						bottom.innerHTML =
							`<div style="position: absolute;color: red;right:0px;font-family: fantasy;background: white;" id="close">关闭</div ><a href="${link}" title="直播视频" target="_blank" rel="noopener noreferrer"><img src="${img}" alt="" class="wp-image-66839" sizes="(max-width: 800px) 100vw, 800px" style="width: 100%; height: 15vh;"></a>`;
						body.insertBefore(bottom, body.lastChild);
						new colos();
					}, 1000) : null;
				}
			}
		}
	}
}

/**
 * sq广告代码配
 */
class pornographic extends func {
	constructor(parameter) {
		super();
		this.init(parameter)
	}
	init(cont) {
		/**
		 * @param {Boolean} filet 是否开启广告过滤
		 * @param {Boolean} linkbg 是否开删除a标签背景图片删除
		 * @param {Boolean} onOff 是否开启广告关闭功能
		 * @param {Object} OneClick 是否开启点击页面跳转 已经配置点击后跳转的页面 和点击后是 是否开启apk 下载
		 * @param {Object} appleplet 广告图片以及广告地址
		 */
		let {
			adapt = 'move', filert = true, linkbg = false, onOff = true, OneClick = {}, appleplet,
		} = cont;
		/**
		 * 注入统计器
		 */
		new statistics();
		/*====================是否开启广告过滤  statr===================*/
		if (filert) {
			new filterImg();
		}
		/*====================是否开启广告过滤  end===================*/

		/**************删除a标签 class 防止注入广告图片为背景图片****************/
		if (linkbg) {
			let AClassName = $.getAll('a');
			for (let pl = 0; pl < AClassName.length; pl++) {
				//当前的连接不包含当前的地址
				if (!AClassName[pl].href.includes(window.location.protocol + "//" + window.location.host)) {
					AClassName[pl].className = '';
					console.log('ClasName')
				}
				if (AClassName[pl].backgroundImage) {
					AClassName[pl].backgroundImage = null;
				}
			}
		}
		const body = $.getBody();
		if (this.getFtu() === '移动端' || adapt === 'All') {
			//屏幕任意点击事件
			OneClick.click && new arbitrarilyClick({
				jumpTerm: OneClick.off,
				linkUrl: OneClick.url,
				download: OneClick.dwApp,
				dwAPK: OneClick.AppUrl
			});
			setTimeout(() => {
				for (let g in appleplet) {
					new template({
						site: appleplet[g].tp,
						a: appleplet[g].url,
						img: appleplet[g].img,
						id: appleplet[g].id,
						className: appleplet[g].className,
						sqcont: appleplet[g].sqcont,
					})
				}
			}, 100);

		}
		//关闭广告			
		onOff && new colos();
	}
}

